home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / DOUBLEDE / PRINT.C < prev    next >
C/C++ Source or Header  |  1988-07-27  |  2KB  |  115 lines

  1. #include <PrintMgr.h>
  2. #include <WindowMgr.h>
  3. #include <DialogMgr.h>
  4. #include <QuickDraw.h>
  5. #include <ToolboxUtil.h>
  6.  
  7.  
  8. #define                NIL        0L
  9.  
  10. static THPrint        hPrint;
  11.  
  12. /*====================================================================
  13.  
  14.     CheckPrintHandle()
  15.     
  16.     allocate print handle if not already done
  17.     
  18. ====================================================================*/    
  19. CheckPrintHandle()
  20. {
  21.     if (!hPrint)
  22.         PrintDefault(hPrint = (TPrint **) NewHandle( sizeof( TPrint )));
  23. }
  24.  
  25. /*====================================================================
  26.  
  27.     dopagesetup()
  28.     
  29.     allow user to do Page Setup dialog
  30.     
  31. ====================================================================*/    
  32. dopagesetup()
  33. {
  34.     InitCursor();
  35.     PrOpen();
  36.     CheckPrintHandle();
  37.     if (PrStlDialog(hPrint)) ;
  38.     PrClose();
  39. }
  40.  
  41. /*====================================================================
  42.  
  43.     HowMany()
  44.     
  45.     returns the number of copies of the document are desired.
  46.     
  47. ====================================================================*/    
  48. HowMany()
  49. {
  50.     return( ((**hPrint).prJob.bJDocLoop==bDraftLoop) ?
  51.                 (**hPrint).prJob.iCopies : 1 );
  52. }
  53.  
  54. /*====================================================================
  55.  
  56.     print_it()
  57.     
  58.     prints to the printer, a QuickDraw routine should replace the
  59.     default routine included
  60.     
  61. ====================================================================*/
  62. print_it()
  63. {
  64.     TPPrPort        printPort;
  65.     TPrStatus        prStatus;
  66.     Rect            pRect;
  67.     int                nCopies;
  68.     GrafPtr            tempPort;
  69.     int                tFont;
  70.     int                tSize;
  71.  
  72.     InitCursor();
  73.  
  74.     GetPort(&tempPort);
  75.     tFont = tempPort->txFont;
  76.     tSize = tempPort->txSize;
  77.  
  78.     PrOpen();
  79.     if (PrError() == noErr){
  80.         /* make sure we have
  81.          a valid print handle    */
  82.         CheckPrintHandle();
  83.  
  84.         /* do job dialog            */
  85.         if (PrJobDialog(hPrint) != 0) {
  86.             /* print the number
  87.                 of copies requested */
  88.             for(nCopies=HowMany(); nCopies>0; nCopies--){
  89.                 printPort = PrOpenDoc(hPrint,0L,0L);
  90.                 SetPort(printPort);
  91.                 TextFont(tFont);
  92.                 TextSize(tSize);
  93.  
  94.                     PrOpenPage(printPort,0L);
  95.                         pRect = (**hPrint).prInfo.rPage;
  96.                         TextFont(tFont);
  97.                         TextSize(tSize);
  98.                         
  99.                         /*
  100.                             your drawing procedure should be called here
  101.                         */
  102.                         MoveTo(pRect.left+4,pRect.top+15);
  103.                         DrawString("\pNo LightspeedC Shell Print Routine Installed");
  104.                     PrClosePage(printPort);
  105.  
  106.                 PrCloseDoc(printPort);
  107.                 PrPicFile(hPrint,0L,0L,0L,&prStatus);
  108.             }
  109.         }
  110.     }
  111.     PrClose();
  112.  
  113.     SetPort(tempPort);
  114. }
  115.